package cn.huaqingcheng.tianshu.core.auth.jwt;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.nio.file.Path;
import java.time.temporal.ChronoUnit;

/**
 * JwtProperties
 */
@Data
@NoArgsConstructor
@ConfigurationProperties(prefix = "auth.jwt")
public class JwtProperties {

    /**
     * 签发人
     */
    private String issuer;

    /**
     * 访问令牌配置
     */
    private TokenConfig access = new TokenConfig(1L, ChronoUnit.HOURS);

    /**
     * 刷新令牌配置
     */
    private TokenConfig refresh = new TokenConfig(7L, ChronoUnit.DAYS);

    /**
     * 允许的时间偏差 单位 秒
     */
    private Long acceptLeeway = 3L;

    /**
     * 公私密钥
     */
    private KeyFileProperties key = new KeyFileProperties();


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class TokenConfig {

        /**
         * 过期时间
         */
        private Long expires = 1L;

        /**
         * 过期时间单位
         */
        private ChronoUnit expiresUnit = ChronoUnit.MINUTES;

    }


    /**
     * KeyFileProperty
     */
    @Data
    @NoArgsConstructor
    public static class KeyFileProperties {

        private String keyId = "";

        /**
         * 公钥文件路径
         */
        private Path publicPath = Path.of("public-key.pem");

        /**
         * 私钥文件路径
         */
        private Path privatePath = Path.of("private-key.pem");

    }

}
